package org.wu.framework.inner.lazy.orm.solon.prop;

import lombok.extern.slf4j.Slf4j;
import org.noear.solon.annotation.Condition;
import org.noear.solon.annotation.Configuration;
import org.noear.solon.annotation.Inject;
import org.wu.framework.lazy.database.datasource.proxy.builder.LazyWideDataSourceBuild;
import org.wu.framework.lazy.orm.core.config.prop.AbstractLazyDataSourceAttribute;
import org.wu.framework.lazy.orm.core.config.prop.LazyDataSourceAttribute;

import javax.sql.DataSource;

/**
 * description 懒人数据源配置 (可选)
 * 默认使用 MysqlDataSource
 *
 * @author Jia wei Wu
 * @date 2021/4/23 下午1:39
 *
 * @see LazyDataSourceAttribute
 */
@Slf4j
@Configuration
@Condition(onProperty = "solon.datasource.url")
@Inject(value = "${solon.datasource}")
public class LazyDataSourceSolonProperties extends AbstractLazyDataSourceAttribute {


    /**
     * 获取数据源
     *
     * @return 数据源
     */
    @Override
    public DataSource doGetDatasource() {
        LazyWideDataSourceBuild lazyWideDataSourceBuild = new LazyWideDataSourceBuild();
        lazyWideDataSourceBuild.url(getUrl())
                .driverName(switchDriverClassName())
                .username(getUsername())
                .password(getPassword());
        return lazyWideDataSourceBuild.build();
    }
}
